#!/usr/bin/env python
#coding=utf-8

#This is a x file for nodemcu, maked by ZeroDay.
#Using this to automate the test procedure.
#Author: openthings@163.com. copyright&GPL V2.
#Last modified 2014-10-17.

import sys
import x_serial

print "xconsole started."
x_serial.isSimulate = 0
x_serial.port = '/dev/ttyUSB2'
x_serial.bandrate = 9600
x_serial.serialopen()

'''
def exeSerial(strCMD):
	print "EXEC: ",strCMD
	#strResult = x_serial.xcmd2("print(\"Hello,world\")")
	strResult = x_serial.xcmd_all(strCMD)
	print "RESP: ",	strResult
'''	

xcmd=""
xkey=""
print ">",

#x_serial.writeln("print(\"Hello,world\")")
x_serial.writeln("print(node.chipid())")
i=0
while(i<=20):
	strline = x_serial.readline()
	if strline.find(">")>=0:	#没有回车换行，只有超时才会返回。
		
		break
	print strline
	i+=1
	print i
'''
while(1):
	#print ">",
	xkey = raw_input(">")
	if xkey=="q":
		break
	if xkey <> "!":	#phase finished.
		xcmd += xkey
	else:		
		print "E:",xcmd
		xcmd = ""
		print ">",

	#exeSerial(xcmd)
'''

x_serial.serialclose()		
print "xconsole Closed."

